Skip to content

Conversation

genuss
Copy link

@genuss genuss commented Aug 1, 2025

Currently VirtualThreadMetrics from micrometer don't work in a native image. Despite that it was tested in #43852, the PR micrometer-metrics/micrometer#6104 broke it due to the fact that native images don't have jdk.management.VirtualThreadSchedulerMXBean.
I'd like to fix it in micrometer, but in the meantime I'd like to propose not to configure the bean if virtual threads aren't enabled. Without them the bean seems redundant.

What do you think?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 1, 2025
@genuss
Copy link
Author

genuss commented Aug 1, 2025

The fix in micrometer appeared easier than I anticipated. Linking the PR micrometer-metrics/micrometer#6584

@nosan
Copy link
Contributor

nosan commented Aug 1, 2025

I don't think the spring.threads.virtual.enabled property should affect the creation of the VirtualThreadMetrics bean. This property is primarily used to determine whether to instantiate a SimpleAsyncTaskExecutor or a ThreadPoolTaskExecutor, or whether to configure the underlying technology with virtual thread awareness.

The VirtualThreadMetrics bean, on the other hand, is related to JVM-level metrics, typically exposed via JFR or JMX. If I use my own Executors.newVirtualThreadPerTaskExecutor(), these metrics should still be available.

@wilkinsona
Copy link
Member

I agree with @nosan. We need to keep these two disconnected so that an application that isn't configured through application properties to use virtual threads can still see metrics about other usages of them. Thanks anyway for the PR, @genuss.

@wilkinsona wilkinsona closed this Aug 1, 2025
@wilkinsona wilkinsona added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged labels Aug 1, 2025
@genuss
Copy link
Author

genuss commented Aug 1, 2025

I didn't think about virtual threads, created not by spring/spring-boot. That's an important use case. Anyway, the fix on micrometer side is trivial, so I'll proceed with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants